import {
  Column,
  CreateDateColumn,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

import { ApiProperty } from '@nestjs/swagger';
import { PostsEntity } from '../../posts/entities/post.entity';

@Entity('category')
export class CategoryEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty({ description: '文章分类名' })
  @Column({ unique: true })
  namePost: string;

  @OneToMany(() => PostsEntity, (post) => post.category)
  posts: Array<PostsEntity>;

  @ApiProperty({ description: '分类图标', nullable: true })
  @Column({ length: 500, comment: '分类图标', nullable: true })
  iconTag: string;

  @ApiProperty({ description: '排序', default: 0 })
  @Column({ comment: '排序', default: 0 })
  sortNo: number;

  @ApiProperty({ description: '状态', default: 1 })
  @Column({ comment: '状态, 1: 正常，0: 停止使用', default: 1 })
  status: number;

  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
    name: 'create_time',
  })
  createTime: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
    name: 'update_time',
  })
  updateTime: Date;
}
